package com.goldcn.file.util;

import com.goldcn.common.exception.ServiceException;
import com.goldcn.common.util.CommonUtils;
import com.goldcn.enumeration.ErrorCodeEnum;

/**
 * Created by Administrator on 2016/9/1.
 */
public class CommonTools {

    private static final String ErrorCode="ERROR_FILE_";


    public static ServiceException createException(ErrorCodeEnum errorCodeEnum) {
        return new ServiceException(errorCodeEnum.getErrorMsg(),
                ErrorCode + errorCodeEnum.getErrorCode());
    }

    /**
     * 系统限制文件类型判断解析
     * @param sourceType 需要验证类型
     * @param permitTypeStr 允许上传类型字串集
     * @return
     */
    public static boolean limitFileType(String sourceType,String permitTypeStr){
        String[] permitTypes=permitTypeStr.split(",");
        if(CommonUtils.isEmpty(sourceType)){
            return false;
        }
        if(permitTypes.length==0){
            return true;
        }
        for(String permitType:permitTypes){
            if(permitType.equalsIgnoreCase(sourceType)){
                return true;
            }
        }
        return false;
    }

}
